package com.transaction.manage.taMapper;

import com.transaction.manage.model.vo.ComboboxVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public interface TaMapper {

    @Select("select t.c_agencyno value,concat(t.c_agencyno,'(' , t.c_agencyname , ')' ) label from " +
            "ta_ttrustagencyinfo t where t.c_agencyno like 'TTTNET%' " +
            "and t.c_agencytype = '1' order by t.c_agencyno")
    List<ComboboxVo> selectAgencyCombobox();

    @Select("select t.c_serialno value,t.c_sourcename label  from ta_tcaptype t ")
    List<ComboboxVo> selectCapTypeCombobox();

    @Select("select t.c_agencyno value,concat(t.c_agencyno,'(' , t.c_agencyname , ')' ) label from " +
            "ta_ttrustagencyinfo t where t.c_parentcode = #{channelCode} " +
            "and t.c_agencytype = '1' order by t.c_agencyno")
    List<ComboboxVo> selectSubChannelCodeCombobox(@Param("channelCode") String channelCode);

    @Select("SELECT t.c_fundcode AS value , concat(t.c_fundcode, '(', t.c_fundname, ')') AS label FROM ta_tfundinfo t ORDER BY t.c_fundcode ")
    List<ComboboxVo> selectFundCodeCombobox();

    List<ComboboxVo> selectFundYieldCombobox(@Param("taFundCodeList") List<String> taFundCodeList);

    List<ComboboxVo> selectFundYieldsCombobox(@Param("taFundCodeList") List<String> taFundCodeList);

    @Insert("INSERT INTO ta_tcustomerinfo (c_custtype, c_custname, c_identitytype, c_identityno, c_fundacco) " +
            "VALUES (#{c_custtype}, #{c_custname}, #{c_identitytype}, #{c_identityno}, #{c_fundacco})")
    void insertCustomerInfo(@Param("c_custtype") String individualOrInstitution,
                            @Param("c_identitytype") String certificateType,
                            @Param("c_identityno") String certificateNo,
                            @Param("c_custname") String investorName,
                            @Param("c_fundacco") String taAccountId);

    @Select("select c_fundacco from ta_tcustomerinfo where c_custtype = #{c_custtype} and c_custname = #{c_custname} " +
            "and c_identitytype = #{c_identitytype} and c_identityno = #{c_identityno} ")
    String seletFundAccoBy4Element(@Param("c_custtype") String individualOrInstitution,
                                   @Param("c_identitytype") String certificateType,
                                   @Param("c_identityno") String certificateNo,
                                   @Param("c_custname") String investorName);

    @Select("select count(*) from ta_tcustomerinfo where c_fundacco = #{c_fundacco} ")
    int seletCustomerCountByFundAcco(@Param("c_fundacco") String fundAcco);

    @Update("update ta_tcustomerinfo set  c_custtype = #{c_custtype} ,c_custname = #{c_custname},c_identitytype = #{c_identitytype},c_identityno = #{c_identityno}" +
            "where c_fundacco = #{c_fundacco} ")
    void updateCustomerInfoBuyFundAcco(@Param("c_custtype") String individualOrInstitution,
                                       @Param("c_identitytype") String certificateType,
                                       @Param("c_identityno") String certificateNo,
                                       @Param("c_custname") String investorName,
                                       @Param("c_fundacco") String taAccountId);

    void insertRequest(@Param("request") LinkedHashMap<String, Object> request);

    Map<String, Object> selectRequestBuyOutRequestNo(@Param("outRequestNo") String outRequestNo);

    void updateTrustContractSumBalance(@Param("contractMap") Map<String, Object> contractMap,
                                       @Param("balance") BigDecimal balance);

    void insertTrustContract(@Param("request") LinkedHashMap<String, Object> request);

    @Select("select count(*) from ta_tcustomerinfo t where t.c_fundacco = #{fundAcco} ")
    int selectFundAccoIsValid(@Param("fundAcco") String fundAcco);

    @Select("select count(*) from ta_tfundinfo t where t.c_fundcode = #{fundCode} ")
    int selectFundCodeIsValid(@Param("fundCode") String fundCode);

    @Select("SELECT t.c_fundacco AS FUNDACCO, t.c_fundCode AS FUNDCODE,t.l_contractserialno CONTRACTSERIALNO,t.c_trustcontractid TRUSTCONTRACTID FROM ta_ttrustcontracts t " +
            "WHERE t.l_contractserialno = #{contractSerialNo} AND t.c_trustcontractid = #{trustContractId} ")
    Map<String, Object> selectContractByContractNo(@Param("contractSerialNo") String contractSerialNo,
                                                   @Param("trustContractId") String trustContractId);

    List<String> selectIncomeFundCode();

    List<String> selectNetFundCode();

    void insertCrmFundDay(@Param("list") List<Map<String, Object>> list);

    void deleteCrmFundDay();

    List<Map<String, Object>> getCrmFundDay(@Param("date") String date);
}
